package utils

import (
    "github.com/beego/beego/v2/core/logs"
    "runtime"
    "path/filepath"
)

// LogMethodEnter 记录方法进入的日志
func LogMethodEnter() {
    pc, file, line, _ := runtime.Caller(1)
    funcName := runtime.FuncForPC(pc).Name()
    fileName := filepath.Base(file)
    logs.Debug(">>> Entering %s (%s:%d)", funcName, fileName, line)
}

// LogMethodExit 记录方法退出的日志
func LogMethodExit(err error) {
    pc, file, line, _ := runtime.Caller(1)
    funcName := runtime.FuncForPC(pc).Name()
    fileName := filepath.Base(file)
    if err != nil {
        logs.Debug("<<< Exiting %s with error: %v (%s:%d)", funcName, err, fileName, line)
    } else {
        logs.Debug("<<< Exiting %s successfully (%s:%d)", funcName, fileName, line)
    }
}
